import { handleActions } from 'redux-actions';
import {
  calcRiskOfColorectalCancer,
  calcRiskOfGastricCancer,
  calcRiskOfFiveHealthHabit,
  calcRiskOfCerebralStroke,
  calcRiskOfCardiacInfarction,
  clear,
} from '../actions/CalcRiskAction';

const initialState = {
  colorectalCancer: {},
  gastricCancer: {},
  fiveHealthHabit: {},
  cerebralStroke: {},
  cardiacInfarction: {},
}

const report = handleActions({
  // 大腸がん
  [calcRiskOfColorectalCancer]: (state, action) => {
    let obj = Object.assign({}, state.colorectalCancer, action.payload);
    return Object.assign({}, state, { colorectalCancer: obj });
  },
  // 胃がん
  [calcRiskOfGastricCancer]: (state, action) => {
    let obj = Object.assign({}, state.gastricCancer, action.payload);
    return Object.assign({}, state, { gastricCancer: obj })
  },
  // ５つの健康習慣
  [calcRiskOfFiveHealthHabit]: (state, action) => {
    let obj = Object.assign({}, state.fiveHealthHabit, action.payload);
    return Object.assign({}, state, { fiveHealthHabit: obj })
  },
  // 脳卒中
  [calcRiskOfCerebralStroke]: (state, action) => {
    let obj = Object.assign({}, state.cerebralStroke, action.payload);
    return Object.assign({}, state, { cerebralStroke: obj })
  },
  // 心筋梗塞
  [calcRiskOfCardiacInfarction]: (state, action) => {
    let obj = Object.assign({}, state.cardiacInfarction, action.payload);
    return Object.assign({}, state, { cardiacInfarction: obj })
  },
  [clear]: () => {
    return Object.assign({}, initialState);
  },
}, initialState);

export default report
